var inval = [],i,j;
function integer(i){
	return isNaN(parseInt(i,10))?0:parseInt(i,10);
}
function cl(e){this.value = "";}
function p(e){
	var i = integer(this.data);
	var j = 8 - i;
	var v = integer(this.value);
	if(i!=4){
		inval[j].value = 10 - v;
	}
}
for(i=0;i<9;i++){
	inval[i] = document.getElementById("val"+i);
	inval[i].onfocus = cl;
	inval[i].onkeyup = p;
	inval[i].data = i;
}
var start = document.getElementById("start");
var numstr = document.getElementById("numstr");
var form = start.form;
var lists = [
	[2,9,4,7,5,3,6,1,8],
	[2,7,6,9,5,1,4,3,8],
	[4,9,2,3,5,7,8,1,6],
	[6,7,2,1,5,9,8,3,4],
	[4,3,8,9,5,1,2,7,6],
	[6,1,8,7,5,3,2,9,4],
	[8,3,4,1,5,9,6,7,2],
	[8,1,6,3,5,7,4,9,2]
];
function go(){
	numstr.value = "";
	var i=0,j=0,k=0,p=0,q=1,arr=[];
	for(j=0;j<8;j++){
		p=0;
		for(i=0;i<9;i++){
			i!=4 && integer(inval[i].value)==lists[j][i] && (p+=1);
		}
		if(p>q){
			q = p;
			arr = lists[j];
		}
	}
	if(arr.length>0){
		for(i=0;i<9;i++){
			inval[i].value = arr[i];
		}
		numstr.value = arr.join("");
	}else{
		numstr.value = "无结果";
	}
}
var unmber = [];
form.onsubmit = function(e){
	try{
		go();
	}catch(err){
		
	}
	return false;
};